<template>
  <div class="product-deal">
    <flexbox>
      <flexbox-item><div class="flex-demo"><span>{{i.realName}}</span><span>{{i.transferCount | changehands}}</span></div></flexbox-item>
      <flexbox-item><div class="flex-demo"><span>{{i.pushDate | datereserve}}</span></div></flexbox-item>
    </flexbox>
    <flexbox>
      <flexbox-item>
        <div class="flex-demo" v-if="i.applyBalance !== 0">需求:<span>{{i.applyBalance}}元</span><span>{{i.applyTerm}}个月</span></div>
          <div class="flex-demo" v-if="i.applyBalance === 0">需求:<span>面议</span></div>
        </flexbox-item>
      <flexbox-item :span="4"><div class="flex-demo" @click="claim(keyindex)"><img src="../../static/img/rengling@2x.png" /><span>我要认领</span></div></flexbox-item>
    </flexbox>
  </div>
</template>
<script>
import { Flexbox, FlexboxItem } from 'vux'
import api from '../api'
import utils from '../utils'
export default {
  props: ['list', 'i', 'keyindex'],
  components: {
    Flexbox,
    FlexboxItem
  },
  methods: {
    claim (index) {
      var timeStamp = String(Number(new Date()))
      var tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
      var self = this
      api.feemessage({
        token: tokenval,
        timestamp: timeStamp,
        userId: this.$store.state.userID,
        id: this.list[index].orderId,
        fromType: 1,
        feeType: 1
      }).then(res => {
        console.log(res)
        if (res.status === '200') {
          this.$vux.confirm.show({
            title: '认领客户',
            content: '认领客户' + this.list[index].realName + '需' + res.data.buy + '元，费用将从您的账户余额中扣除',
            confirmText: '确认支付',
            cancelText: '稍后认领',
            onCancel () {
              console.log('plugin cancel')
            },
            onConfirm () {
              api.claimclient({
                token: tokenval,
                timestamp: timeStamp,
                userId: self.$store.state.userID,
                id: self.list[index].orderId
              }).then(res => {
                console.log(res)
                if (res.status === '200') {
                  self.$router.push('/fly/claimed')
                }
              })
            }
          })
        }
      })
    }
  }
}
</script>
